package com.xmsit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.xmsit.pojo.AdsCarMileageVelocity;
import com.xmsit.pojo.AdsCarMileageVelocityVo;
import com.xmsit.service.AdsCarMileageVelocityService;
import com.xmsit.mapper.AdsCarMileageVelocityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author 徐
* @description 针对表【ads_car_mileage_velocity(速度主题统计)】的数据库操作Service实现
* @createDate 2025-04-18 22:08:58
*/
@Service
public class AdsCarMileageVelocityServiceImpl extends ServiceImpl<AdsCarMileageVelocityMapper, AdsCarMileageVelocity>
    implements AdsCarMileageVelocityService{

    @Autowired
    private AdsCarMileageVelocityMapper adsCarMileageVelocityMapper;

    @Override
    public List<AdsCarMileageVelocityVo> getAdsCarMileageVelocity(AdsCarMileageVelocity adsCarMileageVelocity) {
        PageHelper.startPage(adsCarMileageVelocity.getPage(),adsCarMileageVelocity.getSize());
        LambdaQueryWrapper<AdsCarMileageVelocity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdsCarMileageVelocity::getVin, adsCarMileageVelocity.getVin());
        queryWrapper.eq(AdsCarMileageVelocity::getData, adsCarMileageVelocity.getData());
        List<AdsCarMileageVelocity> adsCarMileageVelocities = adsCarMileageVelocityMapper.selectList(queryWrapper);
        List<AdsCarMileageVelocityVo> adsCarMileageVelocityVos = new ArrayList<>();
        for (AdsCarMileageVelocity carMileageVelocity : adsCarMileageVelocities) {
            Long timestamp = carMileageVelocity.getTimestamps();
            Date date = new Date(timestamp);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String times = sdf.format(date);
            AdsCarMileageVelocityVo adsCarMileageVelocityVo = new AdsCarMileageVelocityVo();
            adsCarMileageVelocityVo.setVin(carMileageVelocity.getVin());
            adsCarMileageVelocityVo.setData(carMileageVelocity.getData());
            adsCarMileageVelocityVo.setTimes(times);
            adsCarMileageVelocityVo.setMileage(carMileageVelocity.getMileage());
            adsCarMileageVelocityVo.setVelocity(carMileageVelocity.getVelocity());
            adsCarMileageVelocityVos.add(adsCarMileageVelocityVo);
        }
        return adsCarMileageVelocityVos;
    }
}




